import { createApp } from "vue";

import { createPinia } from "pinia";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate"; //引入持久化插件

import ElementPlus from "element-plus";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import "element-plus/dist/index.css";
import App from "./App.vue";
import router from "./router";
const pinia = createPinia();
// const {ElmessageBox}=ElementPlus
console.log("ElementPlus", ElementPlus);

router.beforeEach((to, from, next) => {
  console.log(to);

  if (to.meta.requireAuth) {
    // 判断该路由是否需要登录权限
    if (sessionStorage.getItem("Token")) {
      // 通过vuex state获取当前的user是否存在
      next();
    } else {
      next({
        path: "/login",
        // query: { redirect: to.fullPath }, // 将跳转的路由path作为参数，登录成功后跳转到该路由
      });
    }
  } else {
    next();
  }
});
pinia.use(piniaPluginPersistedstate); //将插件添加到 pinia 实例上
const app = createApp(App);
app.use(ElementPlus, { locale: zhCn });
app.use(pinia);
app.use(router);

app.mount("#app");
